
/*******************************************************************************
Paper..........................: Local Incentives and electric vehicle adoption
Date ..........................: March 2024
Task...........................: Master file 
									- declare all paths, globals, etc.
									- run all do files from here
*******************************************************************************/

clear all
sysdir set PLUS "X:\ado\bocode\"

/*******   STATA packages  ****************************************************/
/*
ssc install reghdfe
ssc install egenmore 
ssc install estout
 */
/*******   Set paths   ********************************************************/
global home  L:\3643\felles\JAERE\

global dofiles         ${home}STATA\dofiles\
global tables          ${home}STATA\output\tables\
global figures         ${home}STATA\output\figures\
global ster  		   ${home}STATA\output\ster\
global datain          ${home}STATA\data\in\
global dataout         ${home}STATA\data\out\
global datatemp        ${home}STATA\data\temp\

/*******   Declare globals  ***************************************************/
			
** Couple households
global household    i.year#i.children i.year#i.antpers_i_regstat_famnr i.year#i.secondhome
global employment	i.year#i.employed1 i.year#i.employed2 i.year#i.retired1 i.year#i.retired2
global age 			i.year#c.age1##c.age1 i.year#c.age2##c.age2
global income 		i.year#i.wies1_decile i.year#i.wies2_decile i.year#i.wealth1_decile  i.year#i.wealth2_decile
global education	i.year#i.grputd1 i.year#i.grputd2 
global distance 	i.year#c.dist1##c.dist1##c.dist1      i.year#c.dist2##c.dist2##c.dist2
global time 		i.year#c.time1##c.time1##c.time1      i.year#c.time2##c.time2##c.time2
global FE		    i.year#i.grkrets_num i.year#i.grk_bed1_num i.year#i.grk_bed2_num
global publictime	i.year#c.PublicTransitTime_1##c.PublicTransitTime_1##c.PublicTransitTime_1  i.year#c.PublicTransitTime_2##c.PublicTransitTime_2##c.PublicTransitTime_2  
global publicquality i.year#c.VENTETID_1 i.year#c.BOARDINGS_1  i.year#c.TAKST_1   i.year#c.VENTETID_2 i.year#c.BOARDINGS_2  i.year#c.TAKST_2
global clustervar	grkrets_num grk_bed1_num  grk_bed2_num

** Single-adult households
global householdS   i.year#i.children i.year#i.antpers_i_regstat_famnr i.year#i.secondhome
global employmentS	i.year#i.employed i.year#i.retired
global ageS 		i.year#c.age##c.age
global incomeS 		i.year#i.wies_decile  i.year#i.wealth_decile  
global educationS	i.year#i.grputd
global distanceS 	i.year#c.dist##c.dist##c.dist     
global timeS 		i.year#c.time##c.time##c.time  
global FES		    i.year i.year#i.grkrets_num i.year#i.grk_bed_num  
global publictimeS	i.year#c.PublicTransitTime##c.PublicTransitTime##c.PublicTransitTime    
global publicqualityS i.year#c.VENTETID i.year#c.BOARDINGS  i.year#c.TAKST 
global clustervarS	grkrets_num grk_bed_num  

** Variables needed for main regressions
global KeepOutcome BEV_fam_yes ICE_fam_count car_fam_count  car_fam_yes  
global KeepTreat  toll_fam_mean ptl_fam_km_mean
global KeepControl familienr year children antpers_*  secondhome employed* retired* age* wies*_decile wealth*_decile  grputd* dist* time* grkrets_num grk_*num   PublicTransitTime* VENTETID*  BOARDINGS* TAKST* couple

** Driving regressions     			
global householdD    	children antpers_i_regstat_famnr secondhome 
global employmentD		employed1 employed2 retired1 retired2
global ageD 			c.age1##c.age1 c.age2##c.age2
global incomeD 			i.wies1_decile i.wies2_decile i.wealth1_decile  i.wealth2_decile
global educationD		i.grputd1 i.grputd2 
global distanceD 		c.dist1##c.dist1##c.dist1      c.dist2##c.dist2##c.dist2
global timeD 			c.time1##c.time1##c.time1       c.time2##c.time2##c.time2
global FED		    	grkrets_num grk_bed1_num grk_bed2_num 
global publictimeD		c.PublicTransitTime_1##c.PublicTransitTime_1##c.PublicTransitTime_1      c.PublicTransitTime_2##c.PublicTransitTime_2##c.PublicTransitTime_2   
global clustervarD		grkrets_num grk_bed1_num  grk_bed2_num
global publicqualityD	VENTETID_1 BOARDINGS_1  TAKST_1  VENTETID_2 BOARDINGS_2 TAKST_2  
global selectionD 		days_eu days_hh weight
global carvarD 			diesel gas electric c.diesel#c.diesel_price c.gas#c.gasoline_price c.electric#c.kwh_price	
	
*-------------------------------------------------------------------------------
// Construct main dataset 
*-------------------------------------------------------------------------------

do "${dofiles}1_CreateMainDataset" // Run-time: about 2,5 hours
		*Data in:
				*${datain}househ_wp2
				*${datain}work_grk_2005_2017
				*${datain}househ_select
				*${datain}distances
				*${datain}car_stock_end_of_year
				*${datain}kollektivtransport_grk
				*${datain}KPI
				*${datain}Link_grkrets_regtype1
		*Data out:
				*${dataout}MainDataset
				
do "${dofiles}2_CreateDrivingDataset" // Run-time: about 1,5 hours
		*Data in:
				*${datain}driving_periods
				*${datain}fuel_prices_taxes.xlsx
				*${dataout}MainDataset
		*Data out:
				*${dataout}DrivingDataset
				
*-------------------------------------------------------------------------------
// Make tables 
*-------------------------------------------------------------------------------
do "${dofiles}Table1" // Run-time: about 5 hours
do "${dofiles}Table2" // Run-time: about 5 hours
do "${dofiles}Table3" // Run-time: about 3 hours
do "${dofiles}Table4" // Run-time: about 5 hours
do "${dofiles}Table5" // Run-time: about 2 hours
				
*-------------------------------------------------------------------------------
// Make figures
*-------------------------------------------------------------------------------
do "${dofiles}Figure1" // Run-time: 0.5 minute
do "${dofiles}Figure2" // Run-time: 0.5 minute
do "${dofiles}Figure3" // Run-time: about 3.5 hours
do "${dofiles}Figure4" // Run-time: about 5 hours
				
*-------------------------------------------------------------------------------				
// APPENDIX tables
*-------------------------------------------------------------------------------

do "${dofiles}TableA1" // Run-time: 2 minutes
do "${dofiles}TableA2_A3" // Run-time: 5 minutes
do "${dofiles}TableB1_C1" // Run-time: about 2 hours
do "${dofiles}TableC2" // Run-time: about 2 hours
do "${dofiles}TableC3" // Run-time: about 5 hours
do "${dofiles}TableC4" // Run-time: about 2 hours
do "${dofiles}TableC5" // Run-time: about 2 hours
do "${dofiles}TableD1" // Run-time: 2 minutes
do "${dofiles}TableD2" // Run-time: about 3.5 hours	
do "${dofiles}TableE1_E2" // Run-time: about 5 minutes
			
				
*-------------------------------------------------------------------------------
// APPENDIX figures
*-------------------------------------------------------------------------------

* Figure A1 - Map, not made in stata
do "${dofiles}FigureA2" // Run-time: 2 minutes
do "${dofiles}FigureA3" // Run-time: 20 minutes
do "${dofiles}FigureA4" // Run-time: 30 minutes
do "${dofiles}FigureA5" // Run-time: 5 seconds
do "${dofiles}FigureA6"	// Run-time: 10 minutes
do "${dofiles}FigureB1_B2_B3" // Run-time: about 8 hours
do "${dofiles}FigureB4" // Run-time: about 1 hour
do "${dofiles}FigureB5" // Run-time: about 1 hour
do "${dofiles}FigureD1" // Run-time: 2 minutes
do "${dofiles}FigureD2" // Run-time: 2 minutes
do "${dofiles}FigureD3" // Run-time: 2 minutes
do "${dofiles}FigureD4" // Run-time: 2 minutes
do "${dofiles}FigureD5" // Run-time: 4 minutes
do "${dofiles}FigureD6" // Run-time: about 1 hour
do "${dofiles}FigureE1_E2_F1" // Run-time: about 0.5 hour	
			